package com.chenglu.android.mine.member;

import android.os.Bundle;

import com.chenglu.android.R;
import com.chenglu.android.common.base.BaseActionBarActivity;
import com.chenglu.android.common.net.Constant;
import com.chenglu.android.common.utils.ToastUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.mine.bean.FansListBean;
import com.chenglu.android.mine.bean.MemberCenterBean;
import com.chenglu.android.mine.bean.PosterBean;
import com.chenglu.android.mine.bean.ReturnStringBean;
import com.chenglu.android.mine.member.mvp.contract.MemberContract;
import com.chenglu.android.mine.member.mvp.presenter.MemberPresenter;
import com.tencent.smtt.export.external.interfaces.SslError;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author: lyj
 * @Created: by Copyright 2023 6 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：等级说明
 */
public class MemberLevelActivity extends BaseActionBarActivity<MemberPresenter> implements MemberContract.View {
    @BindView(R.id.webview)
    WebView webview;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_platform;
    }

    @Override
    protected void initView() {
        setCenterText("等级说明");
        mPresenter = new MemberPresenter();
        mPresenter.attachView(this);
        mPresenter.getLevelDescriptions(getToken());

    }


    private void initWebView(String goodsdetail) {

        Utils.webX5init(webview);
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开  防止加载网页时调起系统浏览器
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

                view.loadUrl(goodsdetail);
                return true;
            }

            @Override
            public void onReceivedSslError(WebView var1, SslErrorHandler handler, SslError var3) {
                handler.proceed(); //表示等待证书响应
                //handler.cancel(); //表示挂起连接，为默认方式
                // handler.handleMessage(null); //可做其他处理

            }
        });
//        x5webview.loadUrl(goodsdetail);
        webview.loadDataWithBaseURL(null, goodsdetail, "text/html", "UTF-8", null);

    }

    @Override
    public void getLevelDescriptions(ReturnStringBean bean) {
        if (bean.getCode().equals(Constant.HTTPCODE200)) {
            initWebView(bean.getData());
        } else {
            ToastUtils.show(bean.getMsg());
        }

    }

    @Override
    public void getMemberCenterInfo(MemberCenterBean bean) {

    }

    @Override
    public void getFansPage(FansListBean bean) {

    }

    @Override
    public void getConsumerPage(FansListBean bean) {

    }

    @Override
    public void getPromotionPoster(PosterBean bean) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
